/*
nodejs是单线程循环执行js代码的，执行流程如下：
1. 顺序执行代码；
2. 执行完后顺序执行process.nextTick注册的回调函数；
3. 检查setTimeout注册的函数是否可执行，实则按注册顺序执行，否则忽略；
3. 按顺序执行setImmediate注册的回调函数。 

*/

setImmediate(function(){
	console.log("setImmediate");
	setImmediate(function(){
		console.log("setImmediate-setImmediate");
	});
	setTimeout(function(){
		console.log("setImmediate-setTimeout");
	});
	process.nextTick(function(){
		console.log("setImmediate-nextTick");
	});
});
setTimeout(function(){
	console.log("setTimeout");
	setTimeout(function(){
		console.log("setTimeout-setTimeout");
	});
	setImmediate(function(){
		console.log("setTimeout-setImmediate");
	});
	process.nextTick(function(){
		console.log("setTimeout-nextTick");
	});
});
process.nextTick(function(){
	console.log("nextTick");
	setImmediate(function(){
		console.log("nextTick-setImmediate");
	});
	setTimeout(function(){
		console.log("nextTick-setTimeout");
	});
	process.nextTick(function(){
		console.log("nextTick-nextTick");
	});
});

/*
nextTick
nextTick-nextTick
setTimeout
setTimeout-nextTick
nextTick-setTimeout
setImmediate
setImmediate-nextTick
nextTick-setImmediate
setTimeout-setImmediate
setTimeout-setTimeout
setImmediate-setTimeout
setImmediate-setImmediate

*/